#include "StateMain.h"

#include "userStates.h"

#include "effects/Hollywood.h"

StateMain::StateMain() : BaseState()
{
    title.loadFont("fonts/unispace.ttf", 48);
    title.setColour(Colour(WHITE));
    title.setPosition(60,60);

    mainMenu.setMenuStart(60,180);
    mainMenu.loadFont("fonts/unispace.ttf", 24);
    mainMenu.setTextColour(WHITE);
    mainMenu.setTextSelectionColour(RED);
    mainMenu.addItem(MENU_STRING_ITEM);
    mainMenu.setMenuItemText("Campaign mode");
    mainMenu.addItem(MENU_STRING_ITEM);
    //mainMenu.setMenuItemText("Continue");
    //mainMenu.addItem(MENU_STRING_ITEM);
    mainMenu.setMenuItemText("Single level");
    mainMenu.addItem(MENU_STRING_ITEM);
    mainMenu.setMenuItemText("---");
    mainMenu.setIsSelectable(false);
    mainMenu.addItem(MENU_STRING_ITEM);
    mainMenu.setMenuItemText("Exit");

    GFX::setClearColour(BLACK);

    // default state
    state = stMenu;

    EFFECTS->fadeIn(1000,BLACK);
}


StateMain::~StateMain()
{

}


void StateMain::userInput()
{
    input->update();

#ifdef PLATFORM_PC
    if(input->isQuit())
    {
        nullifyState();
        return;
    }
#endif

    if (input->isStart())
        setNextState(STATE_TITLE);

    switch (state)
    {
    case stMenu:
        if (input->isUp())
            mainMenu.menuUp();
        else if (input->isDown())
            mainMenu.menuDown();

        if (input->isA()) // select menu item
        {
            switch (mainMenu.getSelection())
            {
            case 0: // New game
                setNextState(STATE_DUMMY + 1);
                break;
            case 1: // Custom level
                setNextState(STATE_LEVELSELECT);
                break;
            case 3: // Exit
                nullifyState();
                break;
            default:
                break;
            }
        }
        break;
    }

    input->resetKeys();
}

void StateMain::update()
{
    // states
    switch(state)
    {
    case stMenu:
        mainMenu.update();
        break;
    }
    EFFECTS->update();
}

void StateMain::render()
{
    GFX::clearScreen();

    // states
    switch(state)
    {
    case stMenu:
        title.print("The Pandora Game");
        mainMenu.render();
        break;
    }
    EFFECTS->render();
}
